package com.guigu.qingcheng.servicegoods.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.guigu.qingcheng.pojo.goods.TbBrand;
import com.guigu.qingcheng.servicegoods.mapper.TbBrandMapper;
import com.guigu.qingcheng.servicegoods.service.TbBrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 品牌表 服务实现类
 * </p>
 *
 * @author testjava
 * @since 2020-07-09
 */
@Service
public class TbBrandServiceImpl extends ServiceImpl<TbBrandMapper, TbBrand> implements TbBrandService {

    @Resource
    private TbBrandMapper mapper;

    @Autowired
    private TbBrandService tbBrandService;

    //根据条件查询封装查询对象
    public QueryWrapper<TbBrand> queryWrapper(Map<String, Object> searchMap){
        QueryWrapper<TbBrand> wapper = new QueryWrapper<TbBrand>();
        if(searchMap != null){
            if(searchMap.get("id") != null && !"".equals(searchMap.get("id")))
                wapper.eq("id", searchMap.get("id"));
            if(searchMap.get("name") != null && !"".equals(searchMap.get("name")))
                wapper.like("name", searchMap.get("name"));
            if(searchMap.get("letter") != null && !"".equals(searchMap.get("letter")))
                wapper.eq("letter", searchMap.get("letter"));
        }
        return wapper;
    }
    @Override
    public Page<TbBrand> findPage(Map<String, Object> searchMap, int page, int size) {
        Page<TbBrand> pageBrand = new Page<TbBrand>(page, size);
        QueryWrapper<TbBrand> query = queryWrapper(searchMap);
        IPage<TbBrand> list = this.tbBrandService.page(pageBrand, query);
        return pageBrand;
    }

    @Override
    public List<TbBrand> findList(Map<String, Object> searchMap) {
        QueryWrapper<TbBrand> wrapper = queryWrapper(searchMap);
        List<TbBrand> list = this.tbBrandService.list(wrapper);
        return list;
    }
}
